package com.epam.lissina.entity;

import java.util.Comparator;
import java.util.List;

import com.epam.lissina.collector.Collect;
import com.epam.lissina.separator.TextSeparator;

public class Sentence {

	private List<Word> word;

	public Sentence(String sentence) {
		word = TextSeparator.parseSentence(sentence);
	}

	public List<Word> getWord() {
		return word;
	}

	public static final Comparator<Sentence> wordCountComparator = new Comparator<Sentence>() {
		@Override
		public int compare(Sentence s1, Sentence s2) {
			return s1.getWord().size() - s2.getWord().size();
		}
	};

	@Override
	public String toString() {
		return Collect.join(word, " ");
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((word == null) ? 0 : word.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Sentence other = (Sentence) obj;
		if (word == null) {
			if (other.word != null)
				return false;
		} else if (!word.equals(other.word))
			return false;
		return true;
	}
}
